package com.tiyunge.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tiyunge.common.annotation.Log;
import com.tiyunge.common.core.controller.BaseController;
import com.tiyunge.common.core.domain.AjaxResult;
import com.tiyunge.common.core.page.TableDataInfo;
import com.tiyunge.common.enums.BusinessType;
import com.tiyunge.common.utils.poi.ExcelUtil;
import com.tiyunge.system.domain.SysBanner;
import com.tiyunge.system.service.ISysBannerService;

/**
 * 轮播图 信息操作处理
 * 
 * @author yejiayu
 */
@RestController
@RequestMapping("/system/banner")
public class SysBannerController extends BaseController
{
    @Autowired
    private ISysBannerService bannerService;

    /**
     * 获取轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('content:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBanner banner)
    {
        startPage();
        List<SysBanner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @Log(title = "轮播图管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('content:banner:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBanner banner)
    {
        List<SysBanner> list = bannerService.selectBannerList(banner);
        ExcelUtil<SysBanner> util = new ExcelUtil<SysBanner>(SysBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 根据轮播图编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(bannerService.selectBannerById(id));
    }

    /**
     * 新增轮播图
     */
    @PreAuthorize("@ss.hasPermi('content:banner:add')")
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysBanner banner)
    {
        banner.setCreateBy(getUsername());
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改轮播图
     */
    @PreAuthorize("@ss.hasPermi('content:banner:edit')")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysBanner banner)
    {
        banner.setUpdateBy(getUsername());
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除轮播图
     */
    @PreAuthorize("@ss.hasPermi('content:banner:remove')")
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        bannerService.deleteBannerByIds(ids);
        return success();
    }
}
